package edu.sctu.alex.June.day20150616.enumPractice;


import java.util.EnumMap;
import java.util.EnumSet;

/**
 * Created by user03 on 2015/6/16.
 */
public class LightTest {

    public enum Light{

        RED(1),GREEN(2),YELLOW(3);

        private int code;

        private  Light(int nCode) {

            this.code = nCode;
        }

        @Override
        public String toString(){

            return  String.valueOf(this.code);
        }

    }

    public static void main(String[] args) {
        System.out.println("演示枚举类型的遍历！。。。");

        testTraversalEnum();

        System.out.println("演示EnmuMap对象的使用和遍历。。。");
        
        testEnumMap();

        System.out.println("演示EnmuSet对象的使用和遍历。。。");
        
        testEnumSet();
    }

    private static void testEnumSet() {

        EnumSet<Light> currEnumSet =  EnumSet.allOf(Light.class);

        for(Light alight:currEnumSet){
            System.out.println("当前的EnumSet中的数据为"+alight);

        }     
    }

    private static void testTraversalEnum() {
        Light [] allLight = Light.values();


        for(Light light:allLight) {
            System.out.println("当前灯 name" +light.name());
            System.out.println("当前灯 ordinal" +light.ordinal());
            System.out.println("当前灯"+light);
        }
        
    }

    private static void testEnumMap() {

        EnumMap<Light,String> enumMap = new EnumMap<Light, String>(Light.class);

        enumMap.put(Light.RED,"红灯");
        enumMap.put(Light.GREEN,"绿灯");
        enumMap.put(Light.YELLOW,"黄灯");

        for(Light light: Light.values()){
            System.out.println("[key="+light.name()+",value="+enumMap.get(light)+"]");

        }


  

}
}
